//
//  QinzTimeLine.m
//  QinzTimeLine
//
//  Created by Qinz on 2017/5/23.
//  Copyright © 2017年 Qinz. All rights reserved.

#import "QinzTimeLine.h"
#import "SDAutoLayout.h"
#import "TimeLineCell.h"

@interface QinzTimeLine ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArr;

@end

@implementation QinzTimeLine

-(void)setSuperView:(UIView *)superView DataArr:(NSMutableArray *)dataArr{

    self.frame = superView.bounds;
    [superView addSubview:self];
    
    [self setUp];
    self.dataArr = dataArr;
}
-(void)setUp{

    self.tableView = [[UITableView alloc]init];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self addSubview:self.tableView];
 
    self.tableView.sd_layout.topEqualToView(self).leftEqualToView(self).bottomEqualToView(self).rightEqualToView(self);
}

#pragma mark -- tableView的代理方法
#pragma mark -- 返回多少组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
#pragma mark -- 每组返回多少个
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}
#pragma mark -- 每个cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    TimeLineModel*model = self.dataArr[indexPath.row];
   
    return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[TimeLineCell class] contentViewWidth:self.frame.size.width];
}
#pragma mark -- 每个cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TimeLineCell*cell = [TimeLineCell timeLineCell:tableView];
    
    if (indexPath.row == 0) {
        cell.lineView.sd_layout.topSpaceToView(cell.pointView, 0);
        cell.lineView.backgroundColor = [UIColor grayColor];
        cell.pointView.backgroundColor = [UIColor redColor];
    }else{
        cell.lineView.sd_layout.topSpaceToView(cell.contentView, 0);
        cell.pointView.backgroundColor = [UIColor grayColor];
        cell.lineView.backgroundColor = [UIColor grayColor];
    }
    cell.model = self.dataArr[indexPath.row];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
#pragma mark -- 选择每个cell执行的操作
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}




@end
